import redis

class DRedis():
    def __init__(self):
        self.r = redis.Redis(port=6379,host='localhost')

    #储存方法
    def str_set(self,key,value,time=0):
        if time:
            self.r.setex(key,time,value)
        else:
            self.r.set(key,value)

    #获取方法
    def str_get(self,key):
        res = self.r.get(key)
        if res:
            res = str(res,encoding='utf8')
            return res
        else:
            return None

r = DRedis()
# r.str_set('name',12354,3)
# print(r.str_get('name'))
